﻿/*
* 创建者：LIYINFAI
* 创建时间：2023/10/15 11:40:00
* 描述：
* --------------------------------------
* 修改说明：
* --------------------------------------
*/

using System;
using System.Drawing;
using System.Windows.Forms;

namespace CommonLibrary.Forms
{
    /// <summary>
    /// 等待窗口
    /// </summary>
    public partial class HWFrmWaiting : HWFrmBase
    {
        /// <summary>
        /// 获取等待消息
        /// </summary>
        /// <value>The MSG.</value>
        public string WaitingMessage { get { return labelMessage.Text; } set { labelMessage.Text = value; } }
        /// <summary>
        /// 构造函数
        /// </summary>
        public HWFrmWaiting()
        {
            base.SetStyle(ControlStyles.UserPaint, true);
            base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            base.SetStyle(ControlStyles.DoubleBuffer, true);
            InitializeComponent();
        }
        /// <summary>
        /// 更新等待消息
        /// </summary>
        /// <param name="message"></param>
        public void UpdateMessage(string message)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new Action(() => { UpdateMessage(message); }));
            }
            else
            {
                this.labelMessage.Text = message;
            }
        }
        /// <summary>
        /// 更新大小
        /// </summary>
        /// <param name="frm"></param>
        public void UpdateSize(HWFrmBase frm)
        {
            var height = this.Height;
            var width = this.Width;
            if (frm.Size.Height > this.Size.Height)
            {
                height = frm.Size.Height;
            }
            if (frm.Size.Width > this.Size.Width)
            {
                width = frm.Size.Width;
            }
            var top = 0.5 * (height - this.labelImage.Height - this.labelMessage.Height);
            this.Size = new Size(width, height);
            this.labelTop.Height = (int)top;
        }
        private void timer_Tick(object sender, EventArgs e)
        {
            if (this.labelImage.ImageIndex == this.imageList.Images.Count - 1)
            {
                this.labelImage.ImageIndex = 0;
            }
            else
            {
                this.labelImage.ImageIndex++;
            }
            Application.DoEvents();
        }
        private void HWFrmWaiting_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.timer.Stop();
        }
        private void HWFrmWaiting_Load(object sender, EventArgs e)
        {
            this.timer.Start();
        }
        private void HWFrmWaiting_SizeChanged(object sender, EventArgs e)
        {
        }
    }
}
